package com.wskj.common.utils.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;
import java.net.URL;

/**
 * 获取证书路径工具类
 * @author gun
 */
@Slf4j
public class CertUtils {
    /**
     * 获取证书路径
     * @param payType 1-微信 2-支付宝 3-银联
     * @param certName
     */
    public static String getCertPath(Integer payType,String certName) throws FileNotFoundException {
        // String currentPath = System.getProperty("user.dir");
        // String env = SpringUtils.getApplicationContext().getEnvironment().getActiveProfiles()[0];
        URL url = ResourceUtils.getURL(certName);
        String currentPath = url.getPath().replace("/"+certName,"");
        StringBuffer stringBuffer = new StringBuffer();
        switch (payType){
            case 1:
                stringBuffer.append(currentPath);
                stringBuffer.append("/certs");
                stringBuffer.append("/wx");
                stringBuffer.append("/"+certName);
                break;
            case 2:
                stringBuffer.append(currentPath);
                stringBuffer.append("/certs");
                stringBuffer.append("/ali");
                stringBuffer.append("/"+certName);
                break;
            case 3:
                stringBuffer.append(currentPath);
                stringBuffer.append("/certs");
                stringBuffer.append("/acp");
                stringBuffer.append("/"+certName);
                break;
        }
        String certPath = stringBuffer.toString();
        log.info("打印证书路径:"+certPath);
        return certPath;
    }
}
